package com.net.xpay.common.manager.impl;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractVersionedManager;
import com.net.xpay.common.dao.CommonSysConfigMapper;
import com.net.xpay.common.domain.CommonSysConfig;
import com.net.xpay.common.manager.CommonSysConfigManager;
import com.net.xpay.common.model.search.CommonSysConfigSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
public class CommonSysConfigManagerImpl extends AbstractVersionedManager<CommonSysConfig> implements CommonSysConfigManager{

    @Autowired
    private CommonSysConfigMapper mapper;

    @Override
    protected BasicMapper<Long, CommonSysConfig> getMapper() {
        return mapper;
    }

    @Override
    public List<CommonSysConfig> listAll() {
        return listByCondition(new CommonSysConfig(), new ArrayList<>());
    }

    @Override
    public List<CommonSysConfig> search(CommonSysConfigSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "asc");
        return nonEmptyList(mapper.search(searchModel, page));
        }


    @Override
    public long searchCount(CommonSysConfigSearchModel searchModel) {
            Preconditions.checkArgument(searchModel != null);
            return mapper.searchCount(searchModel);
    }
}
